package com.code.zjm.scan.code.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.zxing.activity.CaptureActivity;

public class ScanCodeActivity extends AppCompatActivity implements View.OnClickListener {
    private Button btScan;
    private TextView tvShowResult;
    private Toolbar toolbar;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_scan_code);
        toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);

        initView();
    }

    private void initView() {
        btScan = (Button) findViewById(R.id.btScan);
        tvShowResult = (TextView) findViewById(R.id.tvShowResult);
        btScan.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.btScan:
                Intent intent = new Intent(ScanCodeActivity.this, CaptureActivity.class);
                startActivityForResult(intent, 0);
                break;
        }
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (resultCode == RESULT_OK) {
            String result = data.getExtras().getString("result");
            tvShowResult.setText(result);
        }

    }
}
